{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 004 空间参考类SpatialReference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 空间参考类可以把wkt的空间参考字符串变成一个个属性信息标识出来\n",
    "* 投影坐标系和地理坐标系的属性信息是不一样的\n",
    "* 投影信息一定会包含所依赖的地理坐标系相关信息"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 代码部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import arcpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "sr = arcpy.SpatialReference(4326)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通用属性部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "|name|标准名称：\t| GCS_WGS_1984 |\n",
      "|type|类型(地理|投影)：| Geographic |\n",
      "|MDomain|测量域的范围：\t| -100000 900719825474.099 |\n",
      "|MFalseOriginAndUnits|测量假定原点及单位：| -100000 10000 |\n",
      "|MResolution|测量分辨率：\t| 0.0001 |\n",
      "|MTolerance|测量容差：\t| 0.001 |\n",
      "|XYResolution|xy 分辨率：\t| 1e-09 |\n",
      "|XYTolerance|xy 容差：\t| 8.983152841195215e-09 |\n",
      "|ZDomain|Z 值域的范围：\t| -100000 900719825474.099 |\n",
      "|ZFalseOriginAndUnits|Z 假定原点和单位：| -100000 10000 |\n",
      "|ZTolerance|Z 分辨率：\t| 0.001 |\n",
      "|ZResolution|Z 容差：\t\t| 0.0001 |\n",
      "|abbreviation|空间参考的缩写名称：|  |\n",
      "|alias|空间参考的别名：\t|  |\n",
      "|domain|xy 属性域的范围：| -400 -400 9006799.25474099 9006799.25474099 |\n",
      "|factoryCode|空间参考编码WKID：| 4326 |\n",
      "|falseOriginAndUnits|假定原点和单位：\t| -400 -400 1000000000 |\n",
      "|hasMPrecision|是否已定义 m 值精度信息：| True |\n",
      "|hasXYPrecision|是否已定义 xy 精度信息：| True |\n",
      "|hasZPrecision|是否已定义 z 值精度信息：| True |\n",
      "|isHighPrecision|是否已设置高程精度：\t| True |\n",
      "|remarks|空间参考的注释字符串|  |\n"
     ]
    }
   ],
   "source": [
    "print(\"|name|标准名称：\\t|\",sr.name,\"|\")\n",
    "print(\"|type|类型(地理|投影)：|\",sr.type,\"|\")\n",
    "print(\"|MDomain|测量域的范围：\\t|\",sr.MDomain,\"|\")\n",
    "print(\"|MFalseOriginAndUnits|测量假定原点及单位：|\",sr.MFalseOriginAndUnits,\"|\")\n",
    "print(\"|MResolution|测量分辨率：\\t|\",sr.MResolution,\"|\")\n",
    "print(\"|MTolerance|测量容差：\\t|\",sr.MTolerance,\"|\")\n",
    "print(\"|XYResolution|xy 分辨率：\\t|\",sr.XYResolution,\"|\")\n",
    "print(\"|XYTolerance|xy 容差：\\t|\",sr.XYTolerance,\"|\")\n",
    "print(\"|ZDomain|Z 值域的范围：\\t|\",sr.ZDomain,\"|\")\n",
    "print(\"|ZFalseOriginAndUnits|Z 假定原点和单位：|\",sr.ZFalseOriginAndUnits,\"|\")\n",
    "print(\"|ZTolerance|Z 分辨率：\\t|\",sr.ZTolerance,\"|\")\n",
    "print(\"|ZResolution|Z 容差：\\t\\t|\",sr.ZResolution,\"|\")\n",
    "print(\"|abbreviation|空间参考的缩写名称：|\",sr.abbreviation,\"|\")\n",
    "print(\"|alias|空间参考的别名：\\t|\",sr.alias,\"|\")\n",
    "print(\"|domain|xy 属性域的范围：|\",sr.domain,\"|\")\n",
    "print(\"|factoryCode|空间参考编码WKID：|\",sr.factoryCode,\"|\")\n",
    "print(\"|falseOriginAndUnits|假定原点和单位：\\t|\",sr.falseOriginAndUnits,\"|\")\n",
    "print(\"|hasMPrecision|是否已定义 m 值精度信息：|\",sr.hasMPrecision,\"|\")\n",
    "print(\"|hasXYPrecision|是否已定义 xy 精度信息：|\",sr.hasXYPrecision,\"|\")\n",
    "print(\"|hasZPrecision|是否已定义 z 值精度信息：|\",sr.hasZPrecision,\"|\")\n",
    "print(\"|isHighPrecision|是否已设置高程精度：\\t|\",sr.isHighPrecision,\"|\")\n",
    "print(\"|remarks|空间参考的注释字符串|\",sr.remarks,\"|\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 如果是地理坐标系，有如下属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "|GCSCode|地理坐标系代码：\t| 4326 |\n",
      "|GCSName|地理坐标系名称：\t| GCS_WGS_1984 |\n",
      "|angularUnitCode|角度单位代码：\t| 9102 |\n",
      "|angularUnitName|角度单位名称：\t| Degree |\n",
      "|datumCode|基准代码：\t| 6326 |\n",
      "|datumName|基准名称：\t| D_WGS_1984 |\n",
      "|flattening|此椭球体的扁率：\t| 0.0033528106647474805 |\n",
      "|longitude|本初子午线的经度：| 0.0 |\n",
      "|primeMeridianCode|本初子午线代码：\t| 8901 |\n",
      "|primeMeridianName|本初子午线名称：\t| Greenwich |\n",
      "|radiansPerUnit|每角度单位的弧度：\t| 0.017453292519943295 |\n",
      "|semiMajorAxis|椭球体的半长轴长度：| 6378137.0 |\n",
      "|semiMinorAxis|椭球体的半短轴长度：| 6356752.314245179 |\n",
      "|spheroidCode|椭球体代码：\t| 7030 |\n",
      "|spheroidName|椭球体名称：\t| WGS_1984 |\n"
     ]
    }
   ],
   "source": [
    "print(\"|GCSCode|地理坐标系代码：\\t|\",sr.GCSCode,\"|\")\n",
    "print(\"|GCSName|地理坐标系名称：\\t|\",sr.GCSName,\"|\")\n",
    "print(\"|angularUnitCode|角度单位代码：\\t|\",sr.angularUnitCode,\"|\")\n",
    "print(\"|angularUnitName|角度单位名称：\\t|\",sr.angularUnitName,\"|\")\n",
    "print(\"|datumCode|基准代码：\\t|\",sr.datumCode,\"|\")\n",
    "print(\"|datumName|基准名称：\\t|\",sr.datumName,\"|\")\n",
    "print(\"|flattening|此椭球体的扁率：\\t|\",sr.flattening,\"|\")\n",
    "print(\"|longitude|本初子午线的经度：|\",sr.longitude,\"|\")\n",
    "print(\"|primeMeridianCode|本初子午线代码：\\t|\",sr.primeMeridianCode,\"|\")\n",
    "print(\"|primeMeridianName|本初子午线名称：\\t|\",sr.primeMeridianName,\"|\")\n",
    "print(\"|radiansPerUnit|每角度单位的弧度：\\t|\",sr.radiansPerUnit,\"|\")\n",
    "print(\"|semiMajorAxis|椭球体的半长轴长度：|\",sr.semiMajorAxis,\"|\")\n",
    "print(\"|semiMinorAxis|椭球体的半短轴长度：|\",sr.semiMinorAxis,\"|\")\n",
    "print(\"|spheroidCode|椭球体代码：\\t|\",sr.spheroidCode,\"|\")\n",
    "print(\"|spheroidName|椭球体名称：\\t|\",sr.spheroidName,\"|\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 如果是投影坐标系，还有如下属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "sr = arcpy.SpatialReference(4548)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "|PCSCode|投影坐标系代码：\t| 4548 |\n",
      "|PCSName|投影坐标系名称：\t| CGCS2000_3_Degree_GK_CM_117E |\n",
      "|azimuth|投影坐标系方位角：| 0.0 |\n",
      "|centralMeridian|投影坐标系的中央经线：| 117.0 |\n",
      "|centralMeridianInDegrees|投影坐标系中央经线（度）：| 117.0 |\n",
      "|centralParallel|投影坐标系的中央纬线：| 0.0 |\n",
      "|classification|地图投影的分类：\t|  |\n",
      "|falseEasting|投影坐标系的东偏移量：| 500000.0 |\n",
      "|latitudeOf1st|投影坐标系第一个点的纬度：| 0.0 |\n",
      "|latitudeOf2nd|投影坐标系第二个点的纬度：| 0.0 |\n",
      "|latitudeOfOrigin|投影坐标系原点的纬度：| 0.0 |\n",
      "|linearUnitCode|线性单位代码：\t| 9001 |\n",
      "|linearUnitName|线性单位名称：\t| Meter |\n",
      "|longitudeOf1st|投影坐标系第一个点的经度：| 0.0 |\n",
      "|longitudeOf2nd|投影坐标系第二个点的经度：| 0.0 |\n",
      "|longitudeOfOrigin|投影坐标系原点的经度：| 0.0 |\n",
      "|metersPerUnit|米/线性单位：\t| 1.0 |\n",
      "|projectionCode|投影代码：\t| 43005 |\n",
      "|projectionName|投影名称：\t| Gauss_Kruger |\n",
      "|scaleFactor|投影坐标系的比例因子：| 1.0 |\n",
      "|standardParallel1|投影坐标系的第一条纬线：| 0.0 |\n",
      "|standardParallel2|投影坐标系的第二条纬线：| 0.0 |\n"
     ]
    }
   ],
   "source": [
    "print(\"|PCSCode|投影坐标系代码：\\t|\",sr.PCSCode,\"|\")\n",
    "print(\"|PCSName|投影坐标系名称：\\t|\",sr.PCSName,\"|\")\n",
    "print(\"|azimuth|投影坐标系方位角：|\",sr.azimuth,\"|\")\n",
    "print(\"|centralMeridian|投影坐标系的中央经线：|\",sr.centralMeridian,\"|\")\n",
    "print(\"|centralMeridianInDegrees|投影坐标系中央经线（度）：|\",sr.centralMeridianInDegrees,\"|\")\n",
    "print(\"|centralParallel|投影坐标系的中央纬线：|\",sr.centralParallel,\"|\")\n",
    "print(\"|classification|地图投影的分类：\\t|\",sr.classification,\"|\")\n",
    "print(\"|falseEasting|投影坐标系的东偏移量：|\",sr.falseEasting,\"|\")\n",
    "print(\"|latitudeOf1st|投影坐标系第一个点的纬度：|\",sr.latitudeOf1st,\"|\")\n",
    "print(\"|latitudeOf2nd|投影坐标系第二个点的纬度：|\",sr.latitudeOf2nd,\"|\")\n",
    "print(\"|latitudeOfOrigin|投影坐标系原点的纬度：|\",sr.latitudeOfOrigin,\"|\")\n",
    "print(\"|linearUnitCode|线性单位代码：\\t|\",sr.linearUnitCode,\"|\")\n",
    "print(\"|linearUnitName|线性单位名称：\\t|\",sr.linearUnitName,\"|\")\n",
    "print(\"|longitudeOf1st|投影坐标系第一个点的经度：|\",sr.longitudeOf1st,\"|\")\n",
    "print(\"|longitudeOf2nd|投影坐标系第二个点的经度：|\",sr.longitudeOf2nd,\"|\")\n",
    "print(\"|longitudeOfOrigin|投影坐标系原点的经度：|\",sr.longitudeOfOrigin,\"|\")\n",
    "print(\"|metersPerUnit|米/线性单位：\\t|\",sr.metersPerUnit,\"|\")\n",
    "print(\"|projectionCode|投影代码：\\t|\",sr.projectionCode,\"|\")\n",
    "print(\"|projectionName|投影名称：\\t|\",sr.projectionName,\"|\")\n",
    "print(\"|scaleFactor|投影坐标系的比例因子：|\",sr.scaleFactor,\"|\")\n",
    "print(\"|standardParallel1|投影坐标系的第一条纬线：|\",sr.standardParallel1,\"|\")\n",
    "print(\"|standardParallel2|投影坐标系的第二条纬线：|\",sr.standardParallel2,\"|\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### sr可以导出为标准的wkt格式的空间参考字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 可以发现所有的属性，都是解析这个wkt结构的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'PROJCS[\"CGCS2000_3_Degree_GK_CM_117E\",GEOGCS[\"GCS_China_Geodetic_Coordinate_System_2000\",DATUM[\"D_China_2000\",SPHEROID[\"CGCS2000\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",117.0],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]];-5123200 -10002100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sr.exportToString()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.11 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "06b308fdbfd5979111721ebbf4de1ae2cbf405c7740d4ab5c57cb4c3e518bed6"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
